<?php
/**
 * Created by PhpStorm.
 * User: prg
 * Date: 2017/3/3
 * Time: 17:00
 */

//用户查看自己月报详情接口
require_once 'db.php';
require_once  'response.php';

header('content-type:text/html;charset:utf-8');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:POST');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

$id = isset($_GET['reportId'])? $_GET['reportId'] : '';

if(!is_numeric($id)) {
    return Response::show(401,'数据不合法');
}

try {
    $connect = Db::getInstance()->connect();
} catch (Exception $e) {
    return Response::show(403,'数据库连接失败',$e->getMessage());
}

$sql = "SELECT report_title,program_content,match_content,target_content,services_content,report_time,check_status FROM report WHERE report_id=?";
$mysqli_stmt = $connect->prepare($sql);
$mysqli_stmt->bind_param('s',$id);

$data = array();

if($mysqli_stmt->execute()) {
    $mysqli_stmt->bind_result($title,$program,$match,$target,$service,$time,$status);
    while ($mysqli_stmt->fetch()) {
        $info['title'] = $title;
        $info['program'] = $program;
        $info['match'] = $match;
        $info['target'] = $target;
        $info['service'] = $service;
        $info['time'] = $time;
        $info['status'] = $status;
        $data[] = $info;
    }
//    var_dump($data);
    if(count($data)>0) {
        return Response::show(200,'月报详情获取成功',$data);
    } else {
        return Response::show(402,'查不到月报内容');
    }

} else {
    return Response::show(404,'月报详情获取失败');
}